package com.sdcqjy.mylibrary.http;

import android.text.TextUtils;

import com.sdcqjy.mylibrary.MD5Util;

/**
 * Created by 52463 on 2018/3/23.
 * 下载任务
 */
public class DownloadTask {
    private int type;//任务状态 ，开始/继续，暂停，取消
    private String url;
    public String path;//储存目录，可以缺省
    public DownloadCallBack downloadCallBack;
    private String name;//这是url的MD5值

    public DownloadTask(int type, String url) {
        this.type = type;
        this.url = url;
    }

    public DownloadTask setPath(String path) {
        this.path = path;
        return this;
    }

    public DownloadTask setDownloadCallBack(DownloadCallBack downloadCallBack) {
        this.downloadCallBack = downloadCallBack;
        return this;
    }

    public String getName() {
        if (TextUtils.isEmpty(name)) {
            name = MD5Util.getMD5(url);
        }
        return name;
    }

    public DownloadTask setType(int type) {
        this.type = type;
        return this;
    }

    public int getType() {
        return type;
    }

    public String getUrl() {
        return url;
    }

    public static final int DownloadTypeStart = 0;//开始/继续
    public static final int DownloadTypePause = 1;//暂停
    public static final int DownloadTypeCancel = 2;//取消
}
